package drg_group.suzhou_2023.MDC;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import drg_group.suzhou_2023.Base;
import drg_group.suzhou_2023.MedicalRecord;
import drg_group.suzhou_2023.ADRG.*;

public class MDCS{
    public static String group(MedicalRecord record){
        String[] mdc_zd={"B68.000","A25.900","A40.300","B66.800x001","B55.200x001","A30.400x001","A54.001","T82.700x010","A75.300x001","A97.000","B39.300","B18.103+N08.0*","B04.x00","A20.101","A23.300","A22.200x001","A49.814","B81.802","B49.x18","B01.801","B78.902+N08.0*","A44.800","B42.100x003","B57.200x001","A19.901","T85.706","A28.200","A56.800","B03.x00","A75.001","B68.901","B89.x01","B88.800x001","A26.900","A49.802","A06.100x002","A92.500","B37.800x088","A23.900x001","A59.900","A31.101","A54.809","A32.701","A26.900x002","B48.000","B03.x00x004","B76.000","A49.200","R50.801","A49.002","A27.800","B76.902","A24.100x003","A75.200x001","B68.900x004","A43.802","B00.001","B01.800x002+N08.0*","B55.000x001","B74.902","A19.900","T85.710","A02.000x005","A24.101","B33.000","A31.800x003","A60.002","B39.500x001","B66.800x007","B01.900x001","B67.400x001","A30.100x003","A49.810","A49.800x014","A30.100x001","B18.904+N08.0*","A24.001","A18.106+N29.1*","B06.900x001","B76.100","A65.x00","B81.400","T82.700x008","B65.800x003","A18.700x002+E35.1*","A21.300","A06.800x003","T81.405","A54.601","B38.800","B49.x00x007","A49.101","A30.400","B76.800","B33.100","B73.x00","A38.x00","B44.800x003","B55.100x001","A51.400x010","B99.x01","A30.900x004","A43.800x001","A36.900x002","B77.803","A44.100","A25.000x001","A96.200","A01.003","B83.800x007","B66.800x004","A79.800x002","B34.400","B40.900","A40.900","B01.800x004","B48.201","A23.900x004","A48.100","A49.804","A66.300","A36.900","A77.200","A52.300","B05.900x005","A41.805","A02.800","B49.x02+E35.8*","B83.200x001","A30.900x003","R50.900x002","A01.400","T82.700x002","A02.001","B55.000x003","B02.900x001","B78.901","B39.400x001","A01.000x007","A98.800","B26.804","B67.600x001","A21.100","A30.500x001","A63.800","B45.800x002","A66.000","A56.400","B42.100x001","A97.900","B83.800x006","B83.800x003","A02.101","A02.002","B05.901","A51.100x001","A92.800","A66.800","A02.100x002","B00.701","A36.804+N16.0*","A52.101","B52.900x001","A31.800x002","A42.700","B48.401","A20.802","A41.804","A42.200x002","B26.800x011","A25.100x001","B55.900","B66.101","B66.500","B46.900x002","A97.200","A18.100x031","A22.100x003","B54.x00x004","A41.300","B49.x11","B02.700","P37.000","B41.800x001","A19.900x005","B74.400x003","A52.100","B05.800x010","B67.903","A42.100","T81.403","A48.400","B42.100","A68.900","A23.100","A94.x01","A63.002","B68.900x003","B01.900x002","B87.100","B76.901","B47.100x001","B88.900x001","A31.802","A31.800x001","A01.000x010","A06.200x001","A20.800x004","T98.200x021","A35.x00x001","B44.800x005","J10.800x002","A02.000x007","A28.801","A18.200x010","A75.000x004","B36.801","B47.000","A21.700","B00.901","A41.806","A01.000x020","A66.200","A98.500x001+N08.0*","B60.000x001","B40.700","B03.x00x002","B88.800x004","A18.813+D77*","B00.202","A50.900","A01.000x009","B81.800x002","A38.x00x013","B71.900","B50.800","T82.701","A21.800","B33.800","B08.200x002","B69.800x003","B78.000","A06.300x001","A18.200x006","B65.300","B43.801","A41.500x087","B58.801+N16.0*","B68.900x002","B41.800x003","B53.000x001","A51.900","A23.000x001","B52.000","A56.301","A44.000","A77.000","A21.700x002","A31.800x004","T81.401","A49.001","A20.900x002","A22.900","A48.300","A77.200x001","T85.702","B39.500","B55.200","A02.100","B05.900x002","A49.800x015","B67.301","B69.800x005","A20.100","B48.300x001","B25.900x001","B66.200","A77.100","B33.801","A92.300x004","A92.900","A30.400x002","B49.x00x013","A40.800","T81.400x002","B25.900x002","A54.900","B33.300x001","A51.302","T81.400x006","A98.200","A42.804","A40.000","B83.000","A50.200","A66.100","A24.000","B34.800x003","A22.200","A26.800x001","B67.904","B76.900x003","B46.500","B79.x00","P37.100","B83.100","B69.900x001","A42.802","A41.506","B74.400x002","B66.901","A31.800x006","A01.100","B69.802","A20.200","A49.813","A67.300","A49.806","B58.900x001","A54.100x002","B00.900x005","T85.700x103","B64.x00","B57.500","B71.100","A23.800","B80.x00","A31.800x005","A41.100x002","B66.100","A95.100","B46.400","A20.700","A21.900x001","A49.811","A18.104+N29.1*","B25.800x001","A18.100x022+N37.8*","A67.900","B66.400x001","B74.200x001","A30.900","T82.700x005","B65.001","B34.200","A54.600x001","B69.805","R50.900","A49.805","B51.900","A40.903+N16.0*","A19.100","B60.800x001","A75.000x002","B65.800x001","B67.401","B74.100x003","A20.300","A93.100","A93.000","B54.x00x006","B60.000","A49.902","T81.400x004","B37.800x085","A31.002","A42.200","A70.x00","A48.801","A52.709+N08.0*","A49.004","B81.100","A27.900x006","A02.900x002","A01.000x004","A01.000x006","A18.107+N29.1*","B81.800x001","B85.200","A57.x00x002","A60.001","A06.200","A24.100x002","A67.100","A92.100","B08.300","A51.300x005","B48.200","B56.000x001","A43.801","A32.803","B42.100x002","A18.206","A54.002","A49.901","B65.101","B67.906","B85.300","B65.200x001","A01.000x014","A59.800x001","A31.901","A51.000","B69.800x008","A99.x00","T81.404","A51.301","A24.400","T85.703","A02.901","A77.000x001","B05.802","B57.200x003","A56.300x001","R50.800x002","B44.801","B77.900","A18.108+N33.0*","B67.600x002","A52.200","B42.900","B48.700","A31.800x007","A92.300x001","A41.400","A01.000x019","B43.100","B34.800x004","B34.400x002","A23.900x003","B00.700","B34.300","A06.000x001","B74.100x002","B37.801","B89.x00","A06.800x002","A31.000x001","A56.000x003","A58.x01","B66.800x003","B77.800x005","B83.000x001","A93.801","B37.400x001+N37.0*","A26.700x001","B37.401+N37.0*","B88.100","B69.804","A52.900","A40.100","A02.900x004","B52.001+N08.0*","A28.100","B08.400x003","B74.100x001","A56.001","B50.801","B83.201","A41.504","B66.800x006","B03.x00x003","B85.000","A28.900","B26.805+N08.0*","A38.x00x011","A53.000x001","A06.000","B40.800","B44.802","A93.200","B90.102+N29.1*","A97.100","B52.800","A02.000x006","B48.400","B85.400","A30.300x001","A22.700","B08.000x001","A26.700","B87.800x001","A01.200","A92.300x003","B50.000","A66.400","A49.201","A67.000","B88.000x002","B83.200x003","A79.000","B08.800x006","B77.800x002","A77.900","A23.903+N16.0*","P37.300","T85.708","A01.000x017","A48.200","B42.700","R50.803","A23.200","A23.100x001","A23.900x006","A42.801","B34.100","A66.900","B74.901","A69.800","A49.815","A41.101","B85.100","B57.100","A40.200","A30.900x002","A01.000x012","A18.212","B33.000x001","B45.100","A18.103+N29.1*","B33.802","B67.700x001","B70.100","B65.800x002","B05.800x009","A77.300","A49.812","B05.900x001","B39.900","T79.300x001","T82.700x011","A77.300x001","B34.102","A49.800x019","A42.805","B75.x00","A43.100","A52.700x012+N08.0*","B66.300","A30.200","A18.211","A18.800x001","A59.001+N37.0*","B66.902","A51.002","B41.700","B74.200x003","A20.000","T81.400x005","A41.503","A50.401","T84.701","A30.300","A01.000x011","B46.800x001","B55.100","A19.900x004","B66.400","A66.600","B74.200x002","A48.100x001","B67.907","A98.400","B88.900x002","A96.100x001","B83.800x002","A06.300","A38.x00x014","T88.000","R68.801","B70.000","B67.905","B83.800x009","R50.901","A02.004","B27.000","A50.400x001","A52.800","A96.800","B88.800x002","A06.001","A57.x00x003","A41.501","B54.x00x008","A27.800x001","A20.801","A54.900x002","A41.200","A51.300x004","B05.800x008","B74.300","T85.700x809","A41.500x083","A53.900","A77.900x001","A53.000x002","B83.400","A30.500","A49.807","A18.101","A43.900","A23.000","A48.100x003","A67.200","B00.205","B74.900","B37.900","A54.602","B51.800","A19.200","B83.900","B37.802","B65.900x007","B67.600x003","A41.803","T82.700x001","A63.003","T85.709","A02.000","A18.806+E35.0*","A24.201","B43.900","B48.000x001","A18.207","A75.000x003","B38.700","A98.000","A49.800x020","A20.803","A49.800x003","B74.000x002","B26.800x004","A78.x00","B65.000x001","A26.000","B27.800","B48.300","B53.100","A31.803","B74.000x001","B27.900x001","B49.x00x021","A48.800","B00.902","B56.900x001","B27.001","B00.900x007","A50.700","R50.802","A19.902","A49.817","A63.001","B07.x00x009","T81.400x001","A01.000x018","A50.000","B34.800x002","B87.300","B68.100","T86.807","B46.100x001+G99.8*","A18.100x025+N29.1*","B65.100x001","A56.302","A31.001","A59.000","A21.300x002","A49.100x005","B02.800x001","A24.000x002","A27.000","A21.301","A49.300","B78.700","T82.700x007","A98.300","A49.808","A32.900","A58.x00","B08.401","A28.000","A38.x00x012","A51.000x002","A52.700x001","A64.x00","A79.801","A18.105+N29.1*","B69.100","A36.800x005+N33.8*","A49.803","B69.800x004","A51.400x001","B83.300","A31.100","B08.200","B37.808","A42.803","A02.000x010","B69.801","A68.000","A75.900","A41.807","A79.900","T82.700x003","T82.700x009","A27.900x005","A49.100x006","A01.000","A49.800x023","B46.800x002","B37.901","A51.304","A92.000","B37.700x001","B51.000","A63.000","B81.801","A51.200","T85.712","T85.700x104","A31.100x002","A32.700","A95.000","T85.700x808","B05.801","A38.x00x010","B43.800","B45.801","B66.300x001","B87.900","B08.800x004","B55.000","B67.902","B83.800x008","A49.301","A48.800x002","A31.801","B44.900x001","B69.803","B77.800x004","A42.800x002","A41.802","A01.000x008","B18.205+N08.0*","B08.000x004","T81.402","B00.204","T82.700x004","A02.003","A06.700","A24.102","B26.800x010","A31.000","B52.000x002+N08.0*","A52.801","A51.303","T98.200x012","A50.600","A49.003","A30.800","A02.000x009","B48.800x001","A06.002","A31.000x005","A79.100","B26.800x008+N08.0*","B99.x00x001","B41.900","B47.900","A93.802","B74.400x001","A19.200x001","A21.800x001","A54.808","A01.300","A69.900","B08.100","A92.400","A98.100","B57.300","B44.100x003","B66.900","A49.000","A51.500","B81.300","B39.400","A49.103","A52.100x011","A22.000","A55.x00","A27.900x002","A21.000","B76.900","A41.000","B34.400x001","A18.208","A31.900x001","A56.200","A95.900","B05.400","B88.200x001","O98.600x001","T85.701","A96.900","B66.800x005","B67.901","B44.700","B88.300","A50.500","A42.900","B83.800x004","B08.801","A41.800x002","A98.400x001","A30.200x001","A30.300x002","A18.700+E35.1*","A24.002","A02.900x003","B08.000x002","B48.402","B65.900x008","B71.000","B74.000x003","A31.102","B65.905+N08.0*","A51.300x003","A92.300x002","A41.502","B65.900x006","A51.201","A69.200","A68.100","B34.000","A24.300","B27.100","A06.900","A18.100x021+N37.8*","A30.000x001","A31.000x004","A44.900","A49.900","B47.100","A60.900","B81.200","B66.800x002","A32.000","A50.100","B74.900x005","B81.000","T80.200","B66.000","A49.100x004","A66.700","B37.700","A18.801+E35.8*","B74.800x001","A49.801","B51.000x001+D77*","A54.500","A20.000x001","B02.900x003","B36.800","B56.100x001","T80.201","B34.300x002","A50.500x001","B74.900x003","B05.803","A77.800","B88.000x003","B26.900x001","A30.900x008","B50.900x001","A96.000","A41.904+N16.0*","A42.000","A54.900x001","A41.900","B38.900","A06.800x001","B42.800","B67.601","B66.000x001","T80.200x004","B34.900","A96.100","A75.100","Z03.000","A27.900x004","B45.700","A92.300","B45.900","A77.100x001","B88.900x003","A30.900x005","A49.102","A28.001","B83.800x005","A50.400","A41.900x004","A74.900","B83.800x001","A48.000","T81.406","B34.801","A51.001","A92.001","A41.801","B53.800x001","B67.302+E35.0*","B02.900x002","A18.209","A41.505","A92.200","A51.300x002","B34.101","A18.210","A79.901","B83.000x002","B74.400","A41.400x001","B71.800","A24.202","T85.711","A06.100","A20.800x005"};
        String[] dept_list={};
        if (!(true && Base.contains(mdc_zd,record.zdList[0]))){
            return "";
        }
        
        Base.groupMessages.putMessage(record.Index,"符合MDCS入组条件，匹配规则：主诊断匹配");
        String result;

        result=SB1.group(record);
        if (result.length()>0){
            return result;
        }

        if (false && record.ssList!=null && record.ssList.length>0 && Base.contains(Base.SS_VALID,record.ssList[0])){
            Base.groupMessages.putMessage(record.Index,"符合SQY入组条件，存在有效手术操作："+String.join(",",Base.Intersect(record.ssList,Base.SS_VALID)));
            return "SQY";
        }

        result=SR1.group(record);
        if (result.length()>0){
            return result;
        }

        result=SS1.group(record);
        if (result.length()>0){
            return result;
        }

        result=ST1.group(record);
        if (result.length()>0){
            return result;
        }

        result=SU1.group(record);
        if (result.length()>0){
            return result;
        }

        result=SV1.group(record);
        if (result.length()>0){
            return result;
        }

        result=SZ1.group(record);
        if (result.length()>0){
            return result;
        }

        Base.groupMessages.putMessage(record.Index,"不符合MDCS的ADRG入组条件");
        return "";
    }
}

